<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <ul>
    <li>sss</li>
    <li>sss</li>
    <li>sss</li>
  </ul>

  <div>ddd</div>
  <div>ddd</div>
  <div>ddd</div>
  <div>ddd</div>


  <script>
    // console.dir(document.querySelectorAll('div'));


    NodeList.prototype.abcd = function (fn1, fn2) {
      // this 表示调用这个方法的 对象
      // console.log(this);  // [li, li, li]
      for (let i = 0; i < this.length; i++) {
        // this[i].addEventListener('click', function () {}); // 这是通用的写法
        this[i].onmouseenter = function () {
          // console.log('hello'); // ???????
          // 事件内部，this表示事件源
          fn1.call(this);
        }
        this[i].onmouseleave = function () {
          // console.log('world'); // ????????
          fn2.call(this);
        }
      }
    }


    document.querySelectorAll('li').abcd(function () {
      this.style.color = 'red';
    }, function () {
      this.style.color = 'blue';
    });


  </script>

</body>

</html>